
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
		<script type="text/javascript" src="js/convertor.js"></script>
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<script src="js/my.js"></script>
		<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
		<link href="css/myui.css" rel="stylesheet" />
		<script src="js/mui.min.js"></script>
		<script src="js/js/binaryajax.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/js/exif.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/js/canvasResize.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="js/jquery-1.9.0.js" charset="utf-8"></script>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=DIEpModxX0HrT2t10ZtF8z0apw9uDjaT" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
		<style type="text/css">
			body {
				background-color: #efeff4;
			}
			
			.mui-content {}
			
			.mui-content a {
				color: #8F8F94;
			}
			
			.mui-content a.active {
				color: #007aff;
			}
			
			.mui-title {
				font-family: simhei;
			}

			.btn_1_Add{
				left: 25%;
			}
			
			.btn_1 {
				position: absolute;
				width: 2.8rem;
			    height: 2.8rem;
			    left: 42%;
			    margin: 0 auto;
			    background: url(img/camera_s.png) 0 0 no-repeat;
			    background-size: 100% 100%;
			    border: none;
			    padding: 0;
			}
			
			.btn_2 {
				position: absolute;
				right: 25%;
				width: 2.8rem;
			    height: 2.8rem;
			    margin: 0 auto;
			    background: url(img/oky.png) 0 0 no-repeat;
			    background-size: 100% 100%;
			    border: none;
			    padding: 0;
			}
			
			body {
				overflow: hidden;
			}
			
			.showimg {
				text-align: center;
			}

			.showimg>img{
				width: 100%;
				height: 20rem;
			}
			.wh_camera_content{
				width: 90%;
			    margin: 0 auto;
			    position: relative;
			    overflow: hidden;
			    height: 3rem;
			}
		</style>
	</head>

	<body>

		<div id="app" class="mui-views" data-view="1">
			<div class="mui-view">
				<div class="mui-navbar">
					<div class="mui-navbar-inner mui-bar mui-bar-nav mui-navbar-center">
						<button type="button" class="mui-left mui-action-back mui-btn  mui-btn-link mui-btn-nav mui-pull-left mui-pull-left_style">
							<span class="mui-icon mui-icon-left-nav"></span>
						</button>
						<h1 class="mui-center mui-title mui-title_fff" style="margin-left: -15px;">我的公益活动</h1>
					</div>
				</div>
				<div class="mui-pages">
					<div id="setting" class="mui-page mui-page-center">
			<!--页面主内容区结束-->
					</div>
				</div>
			</div>
		</div>

		<div class="" style="background: #efeff4;">
			<div class="showimg">
				<img src="img/gongyi_back.png">
			</div>
			<!--<button type="button" class="mui-btn mui-btn-primary mui-btn-block  btn_1" onclick="galleryImgs()">从相册中选择图片</button>-->
			<br>
			<div class="wh_camera_content">
				<button id="confirm" type="button" class="mui-btn mui-btn-success mui-btn-block btn_2" onclick=""></button>
				<button id="camera" type="button" class="mui-btn mui-btn-primary mui-btn-block  btn_1" onclick="cameraimages()"></button>
			</div>
		</div>
	</body>

	<script type="text/javascript">
		mui.init();
		mui.plusReady(function() {
			phoneNum = localStorage.getItem("phoneNum");
					if (phoneNum == "" || phoneNum == null) {
						mui.toast("请先登录！");
						location.href = "login.html";
					}
		})
		console.log(window.location.href);
		var localurl = "";
		var Address="";
		$("#confirm").hide();
		//$("#camera").hide();
		function cameraimages() {
			//每次拍摄或选择图片前清空数组对象
			$("#confirm").hide();
			$("#camera").hide();
			$(".showimg")[0].innerHTML = null;
			var cmr = plus.camera.getCamera();
			cmr.captureImage(function(p) {
				plus.io.resolveLocalFileSystemURL(p, function(entry) {
					localurl = entry.toLocalURL(); //把拍照的目录路径，变成本地url路径，例如file:///........之类的。
					showImg(localurl);
				});
			}, function(e) {
				mui.toast("很抱歉，获取失败 " + e);
				location.href = "home.html";
			});
		}
		// 全局数组对象，添加文件,用于压缩上传使用
		function showImg(url) {
			// 兼容以“file:”开头的情况
			if (0 != url.toString().indexOf("file://")) {
				url = "file://" + url;
			}
			var _div_ = $(".showimg")[0];
			var _img_ = new Image();
			_img_.src = url; // 传过来的图片路径在这里用。
			_img_.onclick = function() {
				plus.runtime.openFile(url);
			};
			_img_.onload = function() {
				var tmph = _img_.height;
				var tmpw = _img_.width;
				var isHengTu = tmpw > tmph;
				var max = Math.max(tmpw, tmph);
				var min = Math.min(tmpw, tmph);
				var bili = min / max;
				if (max > 1200) {
					max = 1200;
					min = Math.floor(bili * max);
				}
				tmph = isHengTu ? min : max;
				tmpw = isHengTu ? max : min;
				// _img_.style.border = "1px solid rgb(200,199,204)";
				// _img_.style.margin = "10px";
				_img_.style.width = "100%";
				_img_.style.height = "380px";
				_img_.onload = null;
				plus.io.resolveLocalFileSystemURL(url, function(entry) {
						entry.file(function(file) {
							//console.log(file.size + '--' + file.name);
							canvasResize(file, {
								width: tmpw,
								height: tmph,
								crop: false,
								quality: 50, //压缩质量
								rotate: 0,
								callback: function(data, width, height) {
									_img_.src = data;
									_div_.appendChild(_img_);
									plus.nativeUI.closeWaiting();
									$(".btn_1").css("left","25%");
									$("#confirm").show();
									$("#camera").show();
								}
							});
						});
					},
					function(e) {
						plus.nativeUI.closeWaiting();
						console.log(e.message);
					});
			};
		};
		$("#confirm").click(function() {
			//getLocation();
			location.href = "welfare.html?position=" + localurl + "";
			//upload();
		});
		$(function() {
			$('#back').click(function() {
				history.go(-1);
			})
		});
	</script>
</html>